Skip to content

JIT: fix RBO constant relop truth evaluation under opt-repeat#129487

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-stress-opt-repeat-issue
Closed

JIT: fix RBO constant relop truth evaluation under opt-repeat#129487
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-stress-opt-repeat-issue

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Under STRESS_OPT_REPEAT/JitOptRepeat, a second optimization iteration could mis-evaluate a constant relop and steer control flow down the wrong branch, reaching an unreachable % 0 path. This change makes redundant-branch optimization type-correct when interpreting constant value numbers and adds a focused regression covering the reported repro shape.

  • JIT fix (RBO constant-VN handling)

    • Updated src/coreclr/jit/redundantbranchopts.cpp to compare constant relop VNs against a zero VN of the actual VN type instead of hardcoding TYP_INT.
    • Applied the same correction in both constant-relop evaluation sites used by branch elimination/jump-threading.
  • Regression coverage

    • Added src/tests/JIT/Regression/JitBlue/Runtime_129386/Runtime_129386.cs.
    • Added src/tests/JIT/Regression/JitBlue/Runtime_129386/Runtime_129386.csproj with JitEnableOptRepeat=1, JitOptRepeat=Fn30000002142, and JitOptRepeatCount=2.
    • Test asserts expected result/trace path and fails on the prior wrong-branch behavior (DivideByZeroException path).
// before
relopValue = (treeNormVN == vnStore->VNZeroForType(TYP_INT)) ? 0 : 1;

// after
relopValue = (treeNormVN == vnStore->VNZeroForType(vnStore->TypeOfVN(treeNormVN))) ? 0 : 1;

Copilot AI requested review from Copilot and removed request for Copilot June 16, 2026 23:34
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 16, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Co-authored-by: JulieLeeMSFT <63486087+JulieLeeMSFT@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 17, 2026 00:24
Copilot AI changed the title [WIP] Fix silent miscompile causing divide-by-zero in JIT stress optimization JIT: fix RBO constant relop truth evaluation under opt-repeat Jun 17, 2026
Copilot AI requested a review from JulieLeeMSFT June 17, 2026 00:24
@AndyAyersMS

Copy link
Copy Markdown
Member

I wonder if the bug is actually elsewhere? How do we end up with a relop VN that is not TYP_INT?

@JulieLeeMSFT

Copy link
Copy Markdown
Member

The relop is:

EQ( AND( V04, ADD(V09, -0xcba13) ), 0 )

  • V04 (loc2) is value-numbered as $c0 {IntCns 0} — a constant 0.
  • So AND(V04, …) folds to $c0 {IntCns 0} (0 & x = 0), and EQ(0, 0)$d3 {IntCns 1} (true).

The relop VN is a legitimately-computed TYP_INT constant 1 — derived from V04 being wrongly value-numbered as constant 0. That's the real bug, and it's upstream of RBO.

Trying a different fix.

@JulieLeeMSFT

Copy link
Copy Markdown
Member

@copilot, this PR does not fix the issue.
Closing and opening a new PR.

@JulieLeeMSFT JulieLeeMSFT deleted the copilot/fix-stress-opt-repeat-issue branch June 17, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants